const fs = require("fs");
const path = require("path");

/** 检查上级并创建目录 */
function checkAndMkDir(path) {
  const arr = path.split("/");
  if (arr.length > 1) {
    let temp = arr[0];
    for (let i = 1; i < arr.length; i++) {
      // 判断源文件是否存在
      const exist = fs.existsSync(temp);
      if (!exist) fs.mkdirSync(temp);
      temp += "/" + arr[i];
    }
  }
}

module.exports = checkAndMkDir;
